package com.TP.www.servlet;

import com.TP.www.po.Coupon;
import com.TP.www.service.CouponPort;
import com.TP.www.service.impl.CouponImpl;

import java.util.List;

import static com.TP.www.constant.Constant.GET_COUPON_BY_STORE_ID;
import static com.TP.www.constant.Constant.SYS_SC;

/**
 * @author 邱彦祥
 * 优惠卷界面
 */
public class CouponMenu {

    /**
     * 展示优惠卷信息
     * @param storeId 店铺id
     */
    public static void show(Integer storeId){
        CouponImpl couponImpl = new CouponImpl();
        while(true){
            int i = 1;
            String choose;
            List<Coupon> coupons = CouponPort.getCouponByStoreId(GET_COUPON_BY_STORE_ID, storeId);
            if (!coupons.isEmpty()) {
                System.out.println("*********优惠卷******");
                for (Coupon coupon : coupons) {
                    System.out.println( i + " 满" + coupon.getInitialNum() + "减" + coupon.getOffNum());
                    i++;
                }
            }else {
                System.out.println("当前无优惠卷信息!请进行添加...");
            }
            System.out.println("***************************");
            System.out.println("*\t\t1.发放优惠卷\t\t\t\t*");
            System.out.println("*\t\t2.删除优惠卷\t\t\t\t*");
            System.out.println("*********************************");
            System.out.println("请输入数字指令(按0返回上级界面)：");
            choose = SYS_SC.nextLine();
            switch (choose){
                case "0":
                    return;
                case "1":
                    couponImpl.createCoupon(storeId);
                    break;
                case "2":
                    int num = couponImpl.getChoose(i);
                    couponImpl.deleteCoupon(coupons.get(num - 1));
                    break;
                default:
                    System.out.println("输入有误，请重新输入...");
            }
        }
    }
}
